//
//  MyCompetitionViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/8/16.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MyCompetitionViewController.h"
#import "FlipTableView.h"
#import "SegmentTapView.h"
#import "MySatrtCompetionViewController.h"
#import "MyMoreCompetionViewController.h"
@interface MyCompetitionViewController ()<FlipTableViewDelegate,SegmentTapViewDelegate>

@property (nonatomic, strong)SegmentTapView *segment;
@property (nonatomic, strong)FlipTableView *flipView;
@property (strong, nonatomic) NSMutableArray *controllsArray;
@end

@implementation MyCompetitionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的赛事";
    [self createNavagationBackBtn];
    [self initSegment];
    [self initFlipTableViewWithInforId:@""];
}
-(void)createNavagationBackBtn{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 6, 67, 23);
    UIImageView *backImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigator_btn_back"]];
    backImg.frame = CGRectMake(-10, 0, 22, 22);
    [backBtn addSubview:backImg];
    UILabel *backText = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 65, 22)];
    backText.text = @"返回";
    backText.font = [UIFont systemFontOfSize:17];
    [backText setBackgroundColor:[UIColor clearColor]];
    [backText setTextColor:[UIColor whiteColor]];
    [backBtn addSubview:backText];
    [backBtn addTarget:self action:@selector(leftBarButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    [self.navigationItem setLeftBarButtonItem:leftButton];
}
-(void)leftBarButtonItemPressed:(UIButton *)btn{
    [self dismissViewControllerAnimated:YES completion:nil];
}

/**
 *  分段选择的标题设置
 *
 */
-(void)initSegment{
    self.segment = [[SegmentTapView alloc] initWithFrame:CGRectMake(0,64, WIDTH, 40) withDataArray:[NSArray arrayWithObjects:@"即将开始",@"更多", nil] withFont:20];
    self.segment.delegate = self;
    self.segment.lineColor = [UIColor yellowColor];
    self.segment.textNomalColor = [UIColor blackColor];
    self.segment.textSelectedColor = [UIColor yellowColor];
    [self.view addSubview:self.segment];
}
-(void)initFlipTableViewWithInforId:(NSString *)inforId{
    MySatrtCompetionViewController *celeVc = [[MySatrtCompetionViewController alloc] init];

    MyMoreCompetionViewController *cataVc = [[MyMoreCompetionViewController alloc] init];
    [self.controllsArray addObject:celeVc];
    [self.controllsArray addObject:cataVc];
    self.flipView = [[FlipTableView alloc] initWithFrame:CGRectMake(0,64 + 40 , WIDTH, HEIGHT - (64 + 40 )) withArray:_controllsArray];
    self.flipView.delegate = self;
    [self.view addSubview:self.flipView];
    
}

#pragma mark -------- select Index
-(void)selectedIndex:(NSInteger)index
{
    NSLog(@"%ld",index);
    [self.flipView selectIndex:index];
    
}
-(void)scrollChangeToIndex:(NSInteger)index
{
    NSLog(@"%ld",index);
    [self.segment selectIndex:index];
}
-(NSMutableArray *)controllsArray{
    if (_controllsArray == nil) {
        _controllsArray = [[NSMutableArray alloc] init];
    }
    return _controllsArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
